package com.unismc.uview.job;

import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.quartz.QuartzJobBean;

import com.unismc.uview.service.CityDataService;
import com.unismc.uview.service.WeatherDataService;
import com.unismc.uview.vo.City;

public class WeatherDataSyncJob extends QuartzJobBean {
	private static final Log logger = LogFactory.getLog(WeatherDataSyncJob.class);
	@Autowired
	private CityDataService cityDataService;
	@Autowired
	private WeatherDataService weatherDataService;
	@Override
	protected void executeInternal(JobExecutionContext context) throws JobExecutionException {
		logger.info("Weather Data Sync Job. Start!");
		// 获取城市列表
		List<City> cityList = null;
		try {
			cityList = cityDataService.listCity();
		} catch (Exception e) {
			logger.error(e.getMessage());
		}
		//遍历城市ID获取天气
		for(City city : cityList) {
			String cityId = city.getCityId();
			logger.info("Weather Data Sync City Id: "+cityId);
			weatherDataService.getDataByCityId(cityId);
		}
		logger.info("Weather Data Sync Job. Finish!");
	}

}
